package jus.aor.mobilagent.hostel;

import java.util.Date;
import java.util.HashMap;

import jus.aor.mobilagent.kernel._Service;

public class Duration implements _Service<Long> {

	private HashMap<String,Date> listeDate = new HashMap<String,Date>();
	
	public Duration(Object... args){}
	
	@Override
	public Long call(Object... params) throws IllegalArgumentException {
		String nameAgent = (String)params[0];
		String req = (String)params[1];
		if(req.equals("deb")){
			listeDate.put(nameAgent,new Date() );
			return (long) 0;
		}else if(req.equals("fin")){
			Date d = listeDate.get(nameAgent);
			if(d!=null){
				return ((new Date()).getTime()- d.getTime());
			}
				return null;
		}
		return null;
	}

}
